package cn.zmit.kuxi.holder;

import com.xdroid.functions.holder.ViewHolderBase;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.zmit.kuxi.R;
import cn.zmit.kuxi.R.id;
import cn.zmit.kuxi.activity.NowShareActivity;
import cn.zmit.kuxi.contants.Url;
import cn.zmit.kuxi.entity.MyWinRecordEntity;
import cn.zmit.kuxi.image.ImageDisplayer;
import cn.zmit.kuxi.interfaces.OnListItemSelectListener;
import cn.zmit.kuxi.interfaces.OnListItemSelectListenerTwo;
import cn.zmit.kuxi.view.MarqueTextView;

/** * @author chenxu @parameter * @return */
public class MyWinRecordHorld extends ViewHolderBase<MyWinRecordEntity> {
	private static OnListItemSelectListenerTwo<MyWinRecordEntity> onListItemSelect;
	private Context context;
	private ImageView pic;
	private TextView title, goodsName, myCount, luncky_num;
	private TextView time;
	private Button shareOrder;
	private RelativeLayout rlRoot;

	@SuppressLint("InflateParams")
	@Override
	public View createView(LayoutInflater layoutInflater) {
		context = layoutInflater.getContext();

		View view = layoutInflater.inflate(R.layout.item_win_record, null);
		pic = (ImageView) view.findViewById(R.id.imag_goodsPic);
		title = (TextView) view.findViewById(R.id.tv_win_title);
		goodsName = (TextView) view.findViewById(R.id.tv_win_title_data);
		myCount = (TextView) view.findViewById(R.id.tv__win_join_num);
		luncky_num = (TextView) view.findViewById(R.id.tv_win_num);
		time = (TextView) view.findViewById(R.id.tv_win_time);
		shareOrder = (Button) view.findViewById(R.id.btn_win_share_order);
		rlRoot = (RelativeLayout) view.findViewById(R.id.rlRoot);
		return view;
	}

	@Override
	public void showData(final int position, final MyWinRecordEntity itemData) {
		if (itemData.getUrl() != null && itemData.getUrl().length() > 0) {
			ImageDisplayer.getInstance().dispalyImageWithRadius(
					Url.IMAGE_PICTURES + itemData.getUrl(), pic, 0);
		} else {
			pic.setImageResource(R.drawable.ic_launcher);
		}
		title.setText("第" + itemData.getTitle() + "期");
		goodsName.setText(itemData.getName());
		myCount.setText("参与：" + itemData.getMy_buy_count() + "次");
		int num = Integer.parseInt(itemData.getLucky_num());
		int luck = num;
		// int deTime = itemData.getOldtime()-itemData.getNowtime();
		luncky_num.setText("幸运号：" + luck + "");
		time.setText("揭晓时间：" + itemData.getTime());
		if (itemData.getContent().equals("null")) {
			shareOrder.setText("晒单");
			shareOrder
					.setBackgroundResource(R.drawable.btn_get_verification_code_red);
			shareOrder.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent();
					Bundle bundle = new Bundle();
					bundle.putString("gp_id", itemData.getGp_id());
					bundle.putString("title", itemData.getTitle());
					bundle.putString("goodsName", itemData.getName());
					bundle.putString("lunckyNum", itemData.getLucky_num());
					intent.putExtras(bundle);
					intent.setClass(context, NowShareActivity.class);
					context.startActivity(intent);
				}
			});
		} else {
			shareOrder.setText("已晒单");
			shareOrder
					.setBackgroundResource(R.drawable.btn_get_verification_code_grey);
			shareOrder.setClickable(false);

		}
	}

	// 回调
	public static void setOnListItemSelectListenerTwo(
			OnListItemSelectListenerTwo<MyWinRecordEntity> onListItemSelectListener) {
		MyWinRecordHorld.onListItemSelect = onListItemSelectListener;
	}

}
